package com.ruoyi.web.controller.example;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.example.domain.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@Anonymous
@RestController
@RequestMapping("/bind")
@Api(tags = "参数绑定")
public class BindController {
    @ApiOperation("根据用户和性别查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "用户名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sex", value = "用户性别", required=true, dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/names")
    public String getUserName(@RequestParam(value="name",required = false) String UseName,
                              @RequestParam(value = "sex",required = false) String sex){
        return "姓名 "+UseName+" 性别 "+sex;
    }
    @ApiOperation("取得用户ID")
    @ApiImplicitParam(name = "id", value = "用户id", required = true,
            paramType = "path",
            dataType = "String", dataTypeClass = String.class)
    @GetMapping("/ids/{id}")
    public String getUserId(@PathVariable("id") String userId){
        return userId;
    }
    @ApiOperation("新增用户")
    @PostMapping("/users")
    public AjaxResult insertUser(@RequestBody User user){
        return AjaxResult.success(user);
    }
}
